home *** CD-ROM | disk | FTP | other *** search
/ Packard Bell - Internet on a CD / internet on a cd.cdr / Internet / sites / Clementine_NASA / image.hqx / Image folder / Macros / Corpus Collosum Macros next >
Encoding:
Text File  |  1991-06-19  |  4.1 KB  |  202 lines

  1. {
  2. This is a set of macros for measuring the area of various regions in the corpus collosum in MRI scans. It assumes that the scans are 256x256, that you are using a 19" monitor, that the Clipboard buffer is set to 600K, and that you have a lot of RAM.
  3.  
  4. This is the procedure:
  5.  
  6. 1) Open or activate the scan to be analyzed and type Z.
  7. 2) Draw a base line using the line tool.
  8. 3) Draw perpendicular lines by typing S or R.
  9. 4) Draw a perpendicular line at an arbitrary location by clicking
  10.    on the base line with the line tool and typing A.
  11. 5) Outline the corpus collosum.
  12. 6) Threshold by typing B.
  13. 7) Measure the areas by clicking inside each region with the wand.
  14. 8) Revert to grayscale by typing G. (Optional)
  15. 9) Dispose of the 768x768 working window by typing D.
  16. }
  17.  
  18. var  {Global variables}
  19.   WindowNum:integer;
  20.   x1,y1,x2,y2,LineWidth:integer;
  21.   size,angle,dx,dy,pi,theta:real;
  22.   width,height,dx,dy,i:integer;
  23.  
  24.  
  25. macro 'Zoom Window [Z]';
  26. var
  27.   top,left,width,height:integer;
  28. begin
  29.   GetPicSize(width,height);
  30.   if width>600 then begin
  31.     PutMessage('Window has already been zoomed.');
  32.     exit;
  33.   end;
  34.   KillRoi;
  35.   WindowNum:=PicNumber;
  36.   SetScaling('Nearest; New Window');
  37.   ScaleAndRotate(3,3,0);
  38.   ChangeValues(254,255,253); {Reserve 254-255(black) for graphics}
  39.   SetForegroundColor(254);
  40.   ApplyLUT;
  41.   SetLineWidth(1);
  42. end;
  43.  
  44.  
  45. procedure DrawPerpendicularLine(x,y:integer);
  46. begin
  47.   moveto(x,height-y);
  48.   lineto(x+size*cos(theta+angle),height-(y+size*sin(theta+angle)));
  49.   moveto(x,height-y);
  50.   lineto(x+size*cos(theta-angle),height-(y+size*sin(theta-angle)));
  51. end;
  52.  
  53.  
  54. procedure DrawLines(nSegments:integer);
  55. begin
  56.   for i:=1 to nSegments-1 do
  57.     DrawPerpendicularLine(x1+round(i*dx/nSegments),y1+round(i*dy/nSegments));
  58. end;
  59.  
  60.  
  61. procedure DrawLeftLine;
  62. var
  63.   nSegments,i:integer;
  64. begin
  65.   nSegments:=5;
  66.   i:=1;
  67.   DrawPerpendicularLine(x1+round(i*dx/nSegments),y1+round(i*dy/nSegments));
  68. end;
  69.  
  70.  
  71. procedure DrawRightLine;
  72. var
  73.   nSegments,i:integer;
  74. begin
  75.   nSegments:=5;
  76.   i:=4;
  77.   DrawPerpendicularLine(x1+round(i*dx/nSegments),y1+round(i*dy/nSegments));
  78. end;
  79.  
  80.  
  81. procedure DrawThePerpendiculars;
  82. begin
  83.   GetLine(x1,y1,x2,y2,LineWidth);
  84.   if (x1<0) or ((x2-x1)<10) then begin
  85.     PutMessage('Select the base line first using the line tool.');
  86.     exit;
  87.   end;
  88.   Fill;
  89.   KillRoi;
  90.   size:=sqrt(sqr(x2-x1)+sqr(y2-y1))/2;
  91.   angle:=90; {degrees}
  92.   pi:=3.14159;
  93.   GetPicSize(width,height);
  94.   y1:=height-y1;
  95.   y2:=height-y2;
  96.   angle:=(angle/180)*pi;
  97.   dx:=x1-x2;
  98.   dy:=y1-y2;
  99.   if dx=0 then begin
  100.     if dy>=0 then theta:=pi/2 else theta:=3/2*pi
  101.   end else begin
  102.     theta:=arctan(dy/dx);
  103.     if dx<0 then theta:=theta+pi;
  104.   end;
  105.   dx:=x2-x1;
  106.   dy:=y2-y1;
  107.   SetForegroundColor(255);
  108.   DrawLines(2);
  109.   DrawLines(3);
  110. end;
  111.  
  112.  
  113. Macro 'Draw Perpendicular Lines-Left[S]';
  114. begin
  115.   DrawThePerpendiculars;
  116.   DrawLeftLine;
  117. end;
  118.  
  119.  
  120. Macro 'Draw Perpendicular Lines-Right[R]';
  121. begin
  122.   DrawThePerpendiculars;
  123.   DrawRightLine;
  124. end;
  125.  
  126.  
  127. macro 'Draw Arbitrary Perpendicular Line [A]';
  128. var
  129.   xx1,yy1,xx2,yy2:integer;
  130.   fraction:real;
  131. begin
  132.   if angle=0 then begin
  133.     PutMessage('Draw the other perpendiclular lines first.');
  134.     exit;
  135.   end;
  136.   if dx=0 then begin
  137.     PutMessage('Draw base line first.');
  138.     exit;
  139.   end;
  140.   GetLine(xx1,yy1,xx2,yy2,LineWidth);
  141.   if not ((xx1>x1) and (xx1<x2)) then begin
  142.     PutMessage('Click with the line tool first.');
  143.     exit;
  144.   end;
  145.   KillRoi;
  146.   fraction:=(xx1-x1)/dx;
  147.   DrawPerpendicularLine(x1+round(dx*fraction),y1+round(dy*fraction));
  148. end;
  149.  
  150.  
  151. macro 'Make Binary [B]';
  152. var
  153.   top,left,width,height:integer;
  154. begin
  155.   GetRoi(top,left,width,height);
  156.   if width=0 then begin
  157.     PutMessage('Please outline first.');
  158.     exit;
  159.   end;
  160.   DrawBoundary;
  161.   KillRoi;
  162.   SetThreshold(255);
  163.   MeasureArea(true);
  164.   MeasureDensity(false);
  165.   LabelParticles(false);
  166.   IncludeInteriorHoles(true);
  167.   WandAutoMeasure(true);
  168.   ResetCounter;
  169.   ShowResults;
  170. end;
  171.  
  172. macro 'Make Grayscale [G]';
  173. begin
  174.   ResetGrayMap;
  175.   KillRoi;
  176. end;
  177.  
  178. macro 'Dispose of Window [D]';
  179. var
  180.   width,height:integer;
  181. begin
  182.   GetPicSize(width,height);
  183.   if width>600
  184.     then dispose
  185.     else exit;
  186.   if windowNum<>0 then SelectPic(WindowNum);
  187. end;
  188.  
  189. macro 'Adjust Areas [Q]';
  190. var
  191.   i:integer;
  192. begin
  193.   for i:=1 to rCount do
  194.     rArea[i]:=rArea[i]/9;
  195.   ShowResults;
  196. end;
  197.  
  198.  
  199.  
  200.  
  201.  
  202.